package com.example.administrator.officeplatform.Audit;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.example.administrator.officeplatform.R;
import com.example.administrator.officeplatform.bean.PayeeInfo;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/12/23.
 */

public class PaypeeAdapter extends RecyclerView.Adapter{


    private List<PayeeInfo> list = new ArrayList<>();
    private Context mContext;
    private String type;

    public PaypeeAdapter(List<PayeeInfo> list, Context mContext ,String type) {
        this.list = list;
        this.mContext=mContext;
        this.type = type;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_pay, null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        return new PersonViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final PersonViewHolder personViewHolder = (PersonViewHolder) holder;
        personViewHolder.position = position;
        PayeeInfo payeeInfo= list.get(position);
        DecimalFormat format = new DecimalFormat("0.00");

        personViewHolder.tv_name.setText("收款人:"+payeeInfo.getPayeeName());
        personViewHolder.tv_money.setText("金额:"+"￥"+format.format(payeeInfo.getMoney()));
        personViewHolder.tv_bm.setText("部门:"+payeeInfo.getDepartmentName());
        personViewHolder.tv_fybm.setText("费用所属部门:"+payeeInfo.getBearDepartmentName());

//        if ("travelExpense".equals(type)){
//            personViewHolder.tv_fybm.setText("费用所属部门:"+payeeInfo.getBearDepartmentName());
//
//        }else {
//            personViewHolder.layout_bm.setVisibility(View.GONE);
//        }

    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class PersonViewHolder extends RecyclerView.ViewHolder {
        public View rootView;
        public int position;
        public TextView tv_bm, tv_name, tv_money,tv_fybm;
        public LinearLayout layout_bm;
        public PersonViewHolder(View itemView) {
            super(itemView);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_money = (TextView) itemView.findViewById(R.id.tv_money);
            tv_bm = (TextView) itemView.findViewById(R.id.tv_bm);
            tv_fybm = (TextView) itemView.findViewById(R.id.tv_fybm);
            layout_bm = (LinearLayout) itemView.findViewById(R.id.layout_bm);

            rootView = itemView.findViewById(R.id.ll);
        }
    }
}